package com.lelouch.bestpractice.mongorepository.tools;

public class Coordinate2Decimal {

    public static double C2D(String Coodinate) {
        String CoodinateWithoutBlank = Coodinate.trim();
        int degreepos = CoodinateWithoutBlank.indexOf("°");
        int minuteCNpos = CoodinateWithoutBlank.indexOf("′");
        int minuteENpos = CoodinateWithoutBlank.indexOf("'");
        int secondCNpos = CoodinateWithoutBlank.indexOf("″");
        int secondENpos = CoodinateWithoutBlank.indexOf("\"");
        String degree = CoodinateWithoutBlank.substring(0, degreepos);
        String minute = CoodinateWithoutBlank.substring(degreepos + 1, minuteCNpos == -1 ? minuteENpos : minuteCNpos);
        String second = CoodinateWithoutBlank.substring((minuteCNpos == -1 ? minuteENpos : minuteCNpos) + 1,
                secondCNpos == -1 ? secondENpos : secondCNpos);

        double result = Double.parseDouble(degree) + Double.parseDouble(minute) / 60 + Double.parseDouble(second) / 3600;
        return result;
    }

}